#include "i2c.h"
sbit I2c_scl=P2^1;
sbit I2c_sda=P2^0;
void I2C_start(){
	I2c_sda=1;
	I2c_scl=1;
	I2c_sda=0;
	I2c_scl=0;
}

void I2C_stop(){
	I2c_sda=0;
	I2c_scl=1;
	I2c_sda=1;
	
}
void I2C_sendack(unsigned char sack){
	I2c_sda=sack;
	I2c_scl=1;
	I2c_scl=0;
}
unsigned  char I2C_acack(){
	unsigned char aack;
	I2c_sda=1;
	I2c_scl=1;
	aack=I2c_sda;
	I2c_scl=0;
	return aack;
}
void I2C_sendbyte(unsigned char byte){
	unsigned char i;
	for(i=0;i<8;i++){
		I2c_sda=byte&(0x80>>i);
		I2c_scl=1;
		I2c_scl=0;
	}
}
unsigned char I2C_acbyte(){
	unsigned char Data=0x00;
	unsigned char i;
	for(i=0;i<8;i++){
		I2c_sda=1;//在接受数据之前，要释放sda
		I2c_scl=1;
		if(I2c_sda)  Data|=(0x80>>i);//释放后sda的值是读取时候的值了
		I2c_scl=0;
	}
	return Data;
}